<template>
  <div class="my_main">
    <head-top head-title="我的" hidden='true'></head-top>
    <div class="head">
      <div class="head_bg" :style="'backgroundImage: url('+info.avatar+')'"></div>
      <div class="head_one">
        <img
          :src="info.avatar || 'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1651318081,2860235060&fm=27&gp=0.jpg'"
          alt="">
      </div>
      <div class="head_two">
        <span>{{info.nickname}}</span>
      </div>
    </div>
    <mt-cell title="业主认证" is-link to="/EditData1">
      <img slot="icon" src="./images/edit@2x.png" width="26" height="26">
    </mt-cell>
    <mt-cell title="我的房屋" is-link to="/my/MyHouse">
      <img slot="icon" src="./images/house@2x.png" width="26" height="26">
    </mt-cell>
    <mt-cell title="业主变更" is-link to="/my/IdentList">
      <img slot="icon" src="./images/change@2x.png" width="26" height="26">
    </mt-cell>
    <mt-cell title="投票记录" is-link to="/my/MyVote">
      <img slot="icon" src="./images/record@2x.png" width="26" height="26">
    </mt-cell>
    <mt-cell title="我的发布" is-link to="/my/MyIdle">
      <img slot="icon" src="./images/myIdle@2x.png" width="26" height="26">
    </mt-cell>
    <mt-cell v-if="adminStatus===1" title="员工入口" is-link to="/my/Entrance">
      <img slot="icon" src="./images/enter@2x.png" width="26" height="26">
    </mt-cell>
    <!--<mt-cell  title="跑楼申请" is-link to="/my/applyRunBuild">-->
    <div class="spice_li" @click="goRunBuild">
      <div class="spice_title">
        <img slot="icon" src="./images/runbuild@2x.png" width="26" height="26">
        <span>跑楼申请</span>
      </div>
      <img class="spice_icon" src="../home/images/back@2x.png" alt="">
    </div>
    <mt-cell title="申请体验" is-link to="/my/Experience">
      <img slot="icon" src="./images/apply_icon@2x.png" width="26" height="26">
    </mt-cell>

    <!--<mt-cell title="关于我们" is-link to="/my/AboutUs"></mt-cell>-->
    <!--<mt-cell title="帮助与意见反馈" is-link to="/my/Opinion"></mt-cell>-->
    <!--<mt-cell title="登录" is-link to="/Login"></mt-cell>-->
    <v-footer></v-footer>
  </div>
</template>
<style lang="scss">
  .my_main {
    width: 100%;
    padding-top: 40px;
    padding-bottom: 20%;
    .mint-cell-wrapper {
      background-position: bottom left;
      background-size: 100% 1px;
      .mint-cell-value {
        span {
          color: #398ede;
          font-size: 13px;
        }
      }
    }
    .no-border {
      .mint-cell-wrapper {
        background-size: 100% 0px;
      }
    }
    .head {
      width: 100%;
      height: 122px;
      position: relative;
      .head_bg {
        position: absolute;
        height: 122px;
        width: 100%;
        top: 0px;
        left: 0;
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
        opacity: 0.2;
      }
      .head_one {
        width: 100%;
        height: 65px;
        padding-top: 20px;
        text-align: center;
        img {
          width: 65px;
          height: 65px;
          border-radius: 50%;
        }
      }
      .head_two {
        width: 100%;
        height: 27px;
        margin-top: 10px;
        text-align: center;
        span {
          font-size: 15px;
        }
        img {
          width: 8px;
          height: 11px;
        }
      }
    }
    .spice_li{
      width: 100%;
      display: flex;
      font-size: 16px;
      align-items: center;
      justify-content: space-between;
      .spice_title{
        display: inline-flex;
        align-items: center;
        padding: 10px;
        span{
          margin-left: 5px;
        }
      }
      .spice_icon{
        width: 9px;
        height: 18px;
        margin-right: 8px;
      }
    }
  }
</style>
<script>
  import headTop from '../header/Header.vue'
  import Footer from '../footer/Footer.vue'
  import bus from '../../common/js/commonvue.js'
  import { getMyInfo } from '../../api/my.js'
  import {
    savePhoneName
  } from '../../common/js/cache.js'
  import { TimeExpired } from '../../common/js/isWeiXin'
  import { getEnter } from '../../api/management'
  import {loadPhoneName} from '../../common/js/cache'
  import {Toast} from 'mint-ui'

  export default {
    name: 'My',
    data () {
      return {
        realName: '',
        phoneNumber: '',
        info: '',
        adminStatus: ''
      }
    },
    components: {
      headTop,
      'v-footer': Footer
    },
    created () {
      bus.$on('passNameTel', (realName, phoneNumber) => {
        this.realName = realName
        this.phoneNumber = phoneNumber
      })
      TimeExpired() // 判断登录时间是否过期
      this._getMyInfo()
      this._getEnter()
    },
    methods: {
      // 头像资料数据
      _getMyInfo () {
        getMyInfo().then(res => {
          if (res.code === 200) {
            this.info = res.data
            const phoneName = {
              phone: res.data.phone,
              name: res.data.real_name
            }
            savePhoneName(phoneName)
          }
        })
      },
      // 管理员
      _getEnter () {
        getEnter().then(res => {
          // console.log(res)
          if (res.code === 200) {
            this.adminStatus = res.data.status
            // console.log(this.adminStatus)
          }
        })
      },
      goRunBuild() {
        // console.log(loadPhoneName())
        if ((loadPhoneName().phone === '0' || loadPhoneName().phone === '') || loadPhoneName().name === '') {
          Toast({
            message: '请先业主认证',
            position: 'middle',
            duration: 3000
          })
          return
        } else {
          this.$router.push('/my/applyRunBuild')
        }
      }
    }
  }
</script>
